<?php

namespace Pyaf\GymBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class RutinaType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('nombre', 'text')
            ->add('descripcion', 'textarea')
            ->add('grupos_musculares', 'entity', array(
                    'class'         => 'Pyaf\\GymBundle\\Entity\\GrupoMusculares',
                    'multiple'  => true,
                    'query_builder' => function ($repositorio) {
                        return $repositorio->createQueryBuilder('p')
                                ->where('p.habilitado = true');
                    },
            ))
            ->add('habilitado', 'checkbox')
        ;
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Pyaf\GymBundle\Entity\Rutina'
        ));
    }

    public function getName()
    {
        return 'pyaf_gymbundle_rutinatype';
    }
}
